package cn.itsource.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.stp.StpUtil;
import cn.itsource.mapper.DriverPointMapper;
import cn.itsource.pojo.domain.DriverPoint;
import cn.itsource.pojo.dto.DriverLocationPoint;
import cn.itsource.result.JSONResult;
import cn.itsource.utils.IdUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program fccar_tt
 * @Description
 * @Author TT
 * @Date 2024/09/27 12:51
 * @Version 1.0
 */
@RestController
@RequestMapping("/hbase")
public class HBaseController {
    @Autowired
    private DriverPointMapper driverPointMapper;

    @GetMapping("/selectByOrderNo/{orderNo}")
    @SaIgnore
    public JSONResult selectByOrderNo(@PathVariable("orderNo") String orderNo){
        return JSONResult.success(driverPointMapper.selectByOrderNo(orderNo));
    }

    /**
     * 将司机的位置保存到hbase
     */
    @GetMapping("/saveDriverLocationForMileage")
    @SaIgnore
    public JSONResult saveDriverLocationForMileage(@RequestBody DriverLocationPoint driverLocationPoint){
        DriverPoint driverPoint = new DriverPoint();
        //设置id
        driverPoint.setId(IdUtil.getSnowFlackId());
        //设置当前登录司机的id值
        driverPoint.setDriverId(StpUtil.getLoginIdAsLong());
        //设置位置
        driverPoint.setLatitude(driverLocationPoint.getLatitude());
        driverPoint.setLongitude(driverLocationPoint.getLongitude());
        //添加
        driverPointMapper.save(driverPoint);
        return JSONResult.success();
    }
}
